package yunwo.cn.yzstation.model;

import android.util.Log;
import android.widget.Toast;

import com.google.gson.Gson;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;
import yunwo.cn.yzstation.api.HttpManager;
import yunwo.cn.yzstation.api.IinventoryModel;
import yunwo.cn.yzstation.api.okapi.GLCallBack;
import yunwo.cn.yzstation.bean.InventoryBean;
import yunwo.cn.yzstation.config.MyConstants;
import yunwo.cn.yzstation.view.activity.InventoryActivity;

/**
 * Created by lao on 2017/9/14.
 */
public class InventoryModel {
    InventoryActivity mInventoryActivity;
    IinventoryModel mIinventoryModel;

    public InventoryModel(InventoryActivity inventoryActivity, IinventoryModel iinventoryModel) {
        this.mInventoryActivity = inventoryActivity;
        this.mIinventoryModel = iinventoryModel;
    }

    public void getData(final String type,int pageNum,int pageSize) {
        Map<String, Object> map = new HashMap<>();
        map.put("trackingStatus", "4,6");

        HttpManager.hpptPostPageString(MyConstants.Inventory,pageNum,pageSize,"create_date desc",map).execute(new GLCallBack() {
            @Override
            public void onResponseT(String result, int code, String msg, int id) {
                if (code == 200) {
                    if (!result.equals("")) {
                        Log.d("xxxxxxxx", result);
                        InventoryBean.DataBean dataBean = new Gson().fromJson(result, InventoryBean.DataBean.class);
                        mIinventoryModel.getListDataSuccess(dataBean,type);
                    }
                }else {
                    mIinventoryModel.getListDataFailure();
                    Toast.makeText(mInventoryActivity, "请求失败"+msg, Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void onError(Call call, Exception e, int id) {
                mIinventoryModel.getListDataFailure();
                Toast.makeText(mInventoryActivity, "请求失败", Toast.LENGTH_SHORT).show();
            }
        });
 /*      HttpManager.hpptGet(MyConstants.Inventory,map).execute(new GLCallBack() {
           @Override
           public void onResponseT(String result, int code, String msg, int id) {
               if (code == 200) {
                   if (!result.equals("")) {
                       Log.d("xxxxxxxx", result);
                       InventoryBean.DataBean dataBean = new Gson().fromJson(result, InventoryBean.DataBean.class);
                       mIinventoryModel.getListDataSuccess(dataBean);
                   }
               }else {
                   Toast.makeText(mInventoryActivity, "请求失败"+code+msg, Toast.LENGTH_SHORT).show();
               }
           }

           @Override
           public void onError(Call call, Exception e, int id) {
               Log.d("qwer",e.toString());
           }
       });*/
    }
}

